package me.minicoral.action;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import me.minicoral.dao.impl.CommentDaoImpl;
import me.minicoral.service.BloggerService;
import me.minicoral.service.UserService;
import me.minicoral.service.impl.BloggerServiceImpl;
import me.minicoral.service.impl.UserServiceImpl;
import me.minicoral.util.MD5Util;

import com.opensymphony.xwork2.ActionSupport;

public class Blogger extends ActionSupport
{

	private static final long serialVersionUID = 1L;

	private String bid; // 微博号
	private String uuid; // 发送这条微博的用户的用户号
	private String bblog; // 微博内容
	private String unick; // 微博内容
	private int bclicksum; // 微博点击量
	private int bpraisesum; // 微博点赞量
	private Date bpubtime; // 微博发布时间
	private int countComment;
	public String getBid()
	{
		return bid;
	}

	public void setBid(String bid)
	{
		this.bid = bid;
	}

	public String getUuid()
	{
		return uuid;
	}

	public void setUuid(String uuid)
	{
		this.uuid = uuid;
	}

	public String getBblog()
	{
		return bblog;
	}

	public void setBblog(String bblog)
	{
		this.bblog = bblog;
	}

	public String getUnick()
	{
		return unick;
	}

	public void setUnick(String unick)
	{
		this.unick = unick;
	}

	public int getBclicksum()
	{
		return bclicksum;
	}

	public void setBclicksum(int bclicksum)
	{
		this.bclicksum = bclicksum;
	}

	public int getBpraisesum()
	{
		return bpraisesum;
	}

	public void setBpraisesum(int bpraisesum)
	{
		this.bpraisesum = bpraisesum;
	}

	public Date getBpubtime()
	{
		return bpubtime;
	}

	public void setBpubtime(Date bpubtime)
	{
		this.bpubtime = bpubtime;
	}

 
	public int getCountComment()
	{
		return countComment;
	}

	public void setCountComment(int countComment)
	{
		this.countComment = countComment;
	}


	@Override
	public String toString()
	{
		return "Blogger [bid=" + bid + ", uuid=" + uuid + ", bblog=" + bblog
				+ ", unick=" + unick + ", bclicksum=" + bclicksum
				+ ", bpraisesum=" + bpraisesum + ", bpubtime=" + bpubtime
				+ ", countComment=" + countComment + "]";
	}


	Map<Object, Object> dataMap = new HashMap<Object, Object>();

	public Map<Object, Object> getDataMap()
	{
		return dataMap;
	}

	private BloggerService s = new BloggerServiceImpl();

	public String showAllBlogger()
	{
		System.out.println("1...." + uuid);
		List<Blogger> bloggers = s.findAllBlogger(uuid);
		System.out.println(bloggers.size());
		for (Blogger blogger : bloggers)
		{
			setCountComment((new CommentDaoImpl().getCommentCount(blogger.bid)));
			System.out.println(blogger);
		}
		dataMap.clear();
		dataMap.put("status", true);
		dataMap.put("message", "查询成功");
		dataMap.put("bloggers", bloggers);
		return SUCCESS;
	}

	public String addBlogger()
	{
		dataMap.clear();
		dataMap.put("status", false);
		dataMap.put("message", "发表失败，请检查网络状态");
		setBid(UUID.randomUUID().toString());
		setBclicksum(0);
		setBpraisesum(0);
		int i = 0;
		System.out.println(this);
		if (bblog != null && uuid != null)
		{
			i = s.addBlogger(this);
			System.out.println(i);
		}
		if (i == 1)
		{
			dataMap.put("status", true);
			dataMap.put("message", "发表成功");
		}
		return SUCCESS;
	}

}
